package com.cskaoyan.market.admin.controller;

import com.cskaoyan.market.admin.service.MarketAddressService;
import com.cskaoyan.market.db.domain.MarketAddress;
import com.cskaoyan.market.util.JacksonUtil;
import com.cskaoyan.market.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author yuanixn2158@163.com
 * @since 2023/05/08 20:02
 */
//http://101.43.69.31:8083/admin/address/list?page=1&limit=20&sort=add_time&order=desc
@RestController
@RequestMapping("/admin/address")
public class AdminAddressController{
    @Autowired
    private MarketAddressService marketAddressService;


    @GetMapping("/**")
    protected void get(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int page = Integer.parseInt(req.getParameter("page"));
        int limit = Integer.parseInt(req.getParameter("limit"));
        String sort = req.getParameter("sort");
        String order = req.getParameter("order");

        List<MarketAddress> marketAddress = marketAddressService.getAddressList(page, limit, sort, order);
        Object ok = ResponseUtil.okList(marketAddress);
        resp.getWriter().println(JacksonUtil.getObjectMapper().writeValueAsString(ok));


    }
}



